﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;

namespace ConsoleApplication
{
    class VehicleInfo
    {
        private readonly static string Provinces = "京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼";
        private readonly static string Upletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        private readonly static string AllChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        private readonly static int[] ProvinceID = new int[] { 11, 12, 13, 14, 15, 21, 22, 23, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 50, 51, 52, 53, 54, 61, 62, 63, 64, 65 };
        private readonly static string[] PhoneNums = new string[] { "133", "153", "180", "189", "130", "131", "132", "155", "156", "185", "186", "134", "135", "136", "137", "138", "139", "150", "151", "152", "157", "158", "159", "182", "183", "187", "188" };
        private static Random rd = new Random();
        public void Create(Int32 Count)
        {
            IList<string> vehicles = new List<string>();
            IList<string> terminals = new List<string>();
            IList<string> simcards = new List<string>();
            for (int i = 0; i < Count; i++)
            {
                vehicles.Add(String.Format("insert into Vehicle(LicensePlate,LicensePlateColor,TransportIndustryCode,TransportBusinessType,VehicleNationality,FK_OrganizationID,FK_VehicleModeID) values('{0}',{1},'021','02100','320211',84,2);", CreateVehicleNum(), rd.Next(1, 5).ToString()));
                terminals.Add(String.Format("insert into Terminal(ProvinceId,CityId,ManufacturerId,TerminalMode,TerminalId,FK_OrganizationID) values({0},100,'MF001','YMTM007','TD{1}',84);", ProvinceID[rd.Next(ProvinceID.Length)].ToString(), (i + 1).ToString().PadLeft(5, '0')));
                simcards.Add(String.Format("insert into SimCard(SimNumber,PhoneNumber,Status,FK_OrganizationID) values('S{0}','{1}',0,84);", (i + 1).ToString().PadLeft(5, '0'), CreatePhoneNum()));
                Thread.Sleep(10);
            }

            File.AppendAllLines(@"C:\Users\Jiangzm\Desktop\Vehicle.sql", vehicles);
            File.AppendAllLines(@"C:\Users\Jiangzm\Desktop\Terminal.sql", terminals);
            File.AppendAllLines(@"C:\Users\Jiangzm\Desktop\Simcard.sql", simcards);
            Console.WriteLine("Success!");
            Console.Read();
        }

        string CreateVehicleNum()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Provinces[rd.Next(Provinces.Length)]);
            sb.Append(Upletters[rd.Next(Upletters.Length)]);
            for (int i = 0; i < 5; i++)
            {
                sb.Append(AllChar[rd.Next(AllChar.Length)]);
                //Thread.Sleep(10);
            }
            return sb.ToString();
        }
        string CreateTerminal()
        {
            return null;
        }
        string CreatePhoneNum()
        {
            return PhoneNums[rd.Next(PhoneNums.Length)] + rd.Next(1000, 9999).ToString().PadLeft(4, '0') + rd.Next(0, 9999).ToString().PadLeft(4, '0');
        }
    }
}
